#include <avz.h>

using namespace AvZ;

void Script()
{
    OpenMultipleEffective('Q', AvZ::MAIN_UI_OR_FIGHT_UI); // 多次生效
    SetAdvancedPauseKey('Z');                             // 按 Z 键控制高级暂停

    SetZombies({
        ZOMBIE,
        POLE_VAULTING_ZOMBIE,
        FOOTBALL_ZOMBIE,
        DANCING_ZOMBIE,
        ZOMBONI,
        JACK_IN_THE_BOX_ZOMBIE,
        DIGGER_ZOMBIE,
        POGO_ZOMBIE,
        BUNGEE_ZOMBIE,
        LADDER_ZOMBIE,
        CATAPULT_ZOMBIE,
        GARGANTUAR,
        GIGA_GARGANTUAR,
        DOLPHIN_RIDER_ZOMBIE,
        SNORKEL_ZOMBIE,
    });

    SelectCards({
        ICE_SHROOM,
        M_ICE_SHROOM,
        COFFEE_BEAN,
        DOOM_SHROOM,
        CHERRY_BOMB,
        LILY_PAD,
        PUFF_SHROOM,
        SUN_SHROOM,
        SCAREDY_SHROOM,
        FLOWER_POT,
    });

    SetTime(-599, 1);
    Card(LILY_PAD, 3, 3);
    pao_operator.autoGetPaoList();
    ice_filler.start({{1, 5}, {6, 5}, {3, 3}});

    for (auto wave : {1, 11})
    {
        // PSD/Bcc 601
        SetTime(291 - 373, wave);
        pao_operator.pao({{2, 9}, {2, 9}}); // PS
        Delay(110);
        pao_operator.pao(1, 8.8); // D
        SetTime(315 - 373);
        pao_operator.pao(5, 8.2); // B

        SetTime(420);
        Card({{PUFF_SHROOM, 5, 9}, {SUN_SHROOM, 6, 9}}); // 垫下半场撑杆

        SetTime(602 - 100 - 198);
        ice_filler.coffee(); // 下波预判 I
    }

    for (auto wave : {2, 12})
    {
        // IPP-PP 1478
        SetTime(-95, wave);
        pao_operator.pao(1, 9); // P 上半场热过渡 实
        SetTime(510 - 373);
        pao_operator.pao(5, 7.4125); // P 下半场热过渡 虚
        SetTime(1224 + 54 - 373);
        pao_operator.pao({{2, 8.55}, {5, 8.55}}); // PP 激活

        SetTime(1224 + 54 + 210 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波 I3
    }

    for (auto wave : {3, 4, 5, 6, 7, 8, 13, 14, 15, 16, 17, 18})
    {
        // I3PPDD-B-PP 1887
        SetTime(410 - 373, wave);
        pao_operator.pao({{1, 8.6625}, {5, 8.6625}}); // PP
        Delay(215);
        if (wave == 3 or wave == 13)
        {
            pao_operator.pao({{1, 8.5875}, {5, 8.5875}});
        }
        else
        {
            pao_operator.pao({{1, 8.5875}, {5, 8.5875}}); // DD w3/w13下半场拦截w1红，炸点左移
        }
        SetTime(1050 - 373);
        if (wave == 13)
        {
            Delay(146);
            pao_operator.pao(3, 8.1375);
        }
        else
        {
            pao_operator.pao(3, 8.275); // B 分离海豚，w13 B复用自w10 D Delay146
        }
        SetTime(1687 - 373);
        pao_operator.pao({{2, 8.3875}, {5, 8.3875}}); // PP 激活

        SetTime(1687 + 210 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波 I3

        if (wave == 3 or wave == 13)
        {
            SetTime(310);
            Shovel({{5, 9}, {6, 9}});
            SetTime(630 + 210 + 74);
            Card({{PUFF_SHROOM, 5, 8}, {SUN_SHROOM, 6, 8}});
            SetTime(1373);
            Shovel({{5, 8}, {6, 8}}); // w3/w13 垫红眼
        }

        if (wave == 8)
        {
            SetTime(1679);
            Card({{LILY_PAD, 3, 8}, {DOOM_SHROOM, 3, 8}}); // 提前放核，用于w9（w18提前种植则核坑未恢复）
        }
    }

    for (auto wave : {9, 19})
    {
        // I3PPDD-B-PPNDD
        SetTime(410 - 373, wave);
        pao_operator.pao({{1, 8.6625}, {5, 8.6625}}); // PP
        Delay(215);
        pao_operator.pao({{1, 8.5875}, {5, 8.5875}}); // DD
        SetTime(1050 - 373);
        pao_operator.pao(3, 8.275); // B 分离海豚
        SetTime(1687 - 373);
        pao_operator.pao({{2, 8.3875}, {5, 8.3875}}); // PP 激活
        SetTime(1687 + 220 - 198 - 100);
        SetPlantActiveTime(ICE_SHROOM, 298);
        if (wave == 19)
        {
            Card({{LILY_PAD, 3, 8}, {DOOM_SHROOM, 3, 8}}); // w19 放核，w9提前放
        }
        Card(COFFEE_BEAN, 3, 8); // N
        SetTime(2070 - 373);
        pao_operator.pao({{1, 8.1}, {5, 8.1}}); // DD

        SetTime(4500 - 200 - 373);
        pao_operator.pao({{2, 9}, {5, 9}});
        SetTime(4300);
        Shovel({{1, 8}, {1, 9}, {2, 8}, {2, 9}, {5, 8}, {5, 9}, {6, 8}, {6, 9}});
    }

    for (auto wave : {10})
    {
        // Nd/NAD 601
        SetTime(291 - 100 - 198, wave);
        Card({{LILY_PAD, 3, 9}, {DOOM_SHROOM, 3, 9}, {COFFEE_BEAN, 3, 9}});
        SetTime(291 - 100);
        Card(CHERRY_BOMB, 5, 9);
        SetTime(401 - 373);
        pao_operator.pao(5, 8.8);
        SetTime(291 + 260 - 373);
        pao_operator.pao(2, 4);
    }

    SetTime(-150, 20);
    pao_operator.pao(4, 7.5875);
    SetTime(-55);
    pao_operator.pao({{2, 9}, {5, 9}, {2, 9}, {5, 9}});
    Delay(125);
    pao_operator.pao({{1, 9}, {5, 9}});
    SetTime(409 - 373);
    pao_operator.pao({{2, 9}, {5, 9}});
    SetTime(5500 - 373);
    pao_operator.pao({{2, 9}, {5, 9}});

    SetTime(0);
    Shovel(3, 3);
    SetTime(5500);
    Shovel({{1, 8}, {1, 9}, {2, 8}, {2, 9}, {5, 8}, {5, 9}, {6, 8}, {6, 9}});

    // w2/12废稿
    // IPP-B-PP 1424 下半场复用需要不使用B
    // SetTime(-95, wave);
    // pao_operator.pao(1, 9); // P 上半场热过渡 实
    // SetTime(510 - 373);
    // pao_operator.pao(5, 7.4125); // P 下半场热过渡 虚
    // SetTime(1050 - 373);
    // pao_operator.pao(3, 8.275); // B 分离海豚
    // SetTime(1224 - 373);
    // pao_operator.pao({{1, 8.375}, {5, 8.375}}); // PP 激活
    //
    // SetTime(1526 + 210 - 100 - 198);
    // SetPlantActiveTime(ICE_SHROOM, 298);
    // ice_filler.coffee(); // 下波 I3
}